import request from './request';
import type { Index, Auth, Music, Common, User, Invitation, TopList, Pay, Ad } from './data';

/**
 * 公共部分
 */
const Common = {
  getQiniuUrl: (data: Common.GetQiniuUrl.Query) =>
    request<Common.GetQiniuUrl.Data>('/infra/file/presigned-url', 'GET', data), // 获取七牛云上传地址
  createNum: (data: Common.UploadUpQiniu.Body) => request<number>('/infra/file/create', 'POST', data), // 后端记录一条上传记录
  config: (data: Common.Config.Query) =>
    request<Common.Config.Data>('/isong/homepage-content/get/content-config', 'POST', data), // 后端记录一条上传记录
  getPoint: (data: { type: number }) => request<number>('/isong/config/getPoint', 'GET', data), // 积分配置获取（创建音乐消耗的A豆数）
  configuration: () => request<Common.Configuration.Data>('/isong/config/get-isong-configuration', 'POST'), // 获取全局配置
};

/**
 * 首页模块
 */
const Index = {
  bannerList: () => request<Index.Banner.Data[]>('/isong/homepage-content/get/slider', 'POST'), // 获取轮播图列表
  adList: () => request<Index.Ad.Data[]>('/isong/homepage-content/get/advertising-space', 'POST'), // 获取广告位列表
  rankList: () => request<Index.Rank.Data[]>('/isong/homepage-content/get/rank', 'POST'), // 获取首页排行榜图
  musicRecommend: () => request<Index.MusicRecommend.Data[]>('/isong/homepage-content/get/music-recommend', 'POST'), // 获取推荐音乐
  memberRecommend: () => request<Index.MemberRecommend.Data[]>('/isong/homepage-content/get/member-recommend', 'POST'), // 获取推荐人
  getUsing: () => request<Index.GetUsing.Data[]>('/isong/homepage-content/get-using', 'GET'), // 获取首页正在使用音乐测评
  videoList: () => request<Index.Video.Data[]>('/isong/homepage-content/get/video', 'GET'), // 获取视频列表
};

/**
 * 登录模块
 */
const Auth = {
  login: (data: Partial<Auth.Login.Body>) =>
    request<Auth.Login.Data>('/member/auth/weixin-mini-app-login', 'POST', data),
  // 发送短息
  sendSmsCode: (data: Auth.SendSms.Body) => request<boolean>('/member/auth/send-sms-code', 'POST', data),
  // 手机验证码登录
  smsLogin: (data: Auth.SmsLogin.Body) => request<Auth.SmsLogin.Data>('/member/auth/sms-login', 'POST', data),
  logout: () => request<boolean>('/member/auth/logout', 'POST'), // 登出
};

/**
 * 用户模块
 */
const User = {
  get: () => request<User.Get.Data>('/member/user/get', 'GET'),
  update: (data: User.Update.Body) => request<boolean>('/member/user/update', 'PUT', data),
  pointPage: (data: User.PointPage.Query) =>
    request<User.PointPage.Data>('/member/point/record/point-page', 'GET', data), // 获取用户A豆记录分页
  getPoint: () => request<number>('/member/user/get-point', 'GET'), // 获取用户剩余A豆
  levelDetail: (data: User.LevelDetail.Query) =>
    request<User.LevelDetail.Data>('/isong/member/get/member/level/detail', 'GET', data), // 用户等级详情
  signIn: () => request<User.SignIn.Data>('/member/sign-in/record/create', 'POST'), // 签到
  getSignInStatus: () => request<User.GetSignInStatus.Data>('/member/sign-in/record/get-summary', 'GET'), // 获取签到状态
};

/**
 * 订单模块
 */
const Order = {
  addProduct: (data: Music.Create.Body) => request<number>('/isong/mall/add-product', 'POST', data), // 添加商品
  productDetail: (data: Music.Create.Body) => request<number>('/isong/mall/product-detail', 'POST', data), // 商品详情
  productUpdate: (data: Music.Create.Body) => request<number>('/isong/mall/product-update', 'POST', data), // 上架下架商品
  productModify: (data: Music.Create.Body) => request<number>('/isong/mall/product-modify', 'POST', data), // 商品修改
  productDelete: (data: Music.Create.Body) => request<number>('/isong/mall/product-delete', 'POST', data), // 商品删除
  goodPage: (data: Music.Create.Body) => request<number>('/isong/mall/get-product-page', 'POST', data), // 我的小店商品列表
  orderPage: (data: Music.Create.Body) => request<number>('/isong/mall/order-page', 'POST', data), // 销售订单列表
  orderDetail: (data: Music.Create.Body) => request<number>('/isong/mall/order-detail', 'POST', data), // 订单详情
  purchasePage: (data: Music.Create.Body) => request<number>('/isong/mall/purchase-page', 'POST', data), // 我的购买列表
  productPage: (data: Music.Create.Body) => request<number>('/isong/mall/product-page', 'POST', data), // 商品分页列表
  purchaseProduct: (data: Music.Create.Body) => request<number>('/isong/mall/purchase-product', 'POST', data), // 购买
  cancelOrder: (data: Music.Create.Body) => request<number>('/isong/mall/cancel-order', 'POST', data), // 购买取消
}

/**
 * 音乐模块
 */
const Music = {
  list: (data: Music.List.Body) => request<Music.List.Data>('/isong/music/page', 'GET', data), // 音乐广场分页
  detail: (data: { id: number }) => request<Music.Detail.Data>('/isong/music/get', 'GET', data), // 音乐广场详情
  myList: (data: Music.List.Body) => request<Music.List.Data>('/isong/music/my-page', 'GET', data), // 我的音乐分页
  myDetail: (data: { id: number }) => request<Music.Detail.Data>('/isong/music/my-get', 'GET', data), // 我的音乐详情
  create: (data: Music.Create.Body) => request<number>('/isong/music/create', 'POST', data), // 创建音乐
  delete: (data: Pick<Music.Create.Body, 'id'>) => request<number>('/isong/music/delete?id=' + data.id, 'DELETE'), // 删除音乐
  update: (data: Pick<Music.Create.Body, 'id' | 'isShowScore' | 'isShowMusic' | 'coverUrl' | 'isShowEvaluation'>) =>
    request<number>('/isong/music/update', 'PUT', data), // 修改音乐
  getMusicMember: (data: Music.GetMusicMember.Body) =>
    request<Music.GetMusicMember.Data>('/isong/music/get-music-member', 'GET', data), // 获取音乐人详情及音乐人音乐列表
  getMusicEvaluation: (data: Music.GetMusicEvaluation.Body) =>
    request<Music.GetMusicEvaluation.Data>('/isong/evaluation-record/get-music-id', 'GET', data), // 根据音乐获得音乐测评记录
  comment: (data: Music.Comment.Query) => request<Music.Comment.Data>('/isong/comment/page', 'GET', data), // 获得评论分页
  childComment: (data: Music.Comment.Query & { topId: number }) =>
    request<Music.Comment.Data>('/isong/comment/child-page', 'GET', data), // 获得子评论分页
  createComment: (data: Music.Comment.Create.Body) => request<number>('/isong/comment/create', 'POST', data), // 创建评论
  handleLikes: (data: Music.HandleLikes.Query) =>
    request<Music.LikesList.Data[]>('/isong/music/handle-likes', 'GET', data), // 点赞和取消点赞
  likesList: (data: Music.LikesList.Query) => request<number>('/isong/music/likes-list', 'GET', data), // 点赞列表
  addPlayNum: (data: { id: number }) => request<number>('/isong/music/add-play-num', 'GET', data), // 播放数+1
  getPoster: (data: { id: number }) => request<string>('/isong/music/getPoster', 'GET', data), // 分享海报
};

/**
 * 邀请模块
 */
const Invitation = {
  list: (data: Invitation.List.Body) =>
    request<Invitation.List.Data>('/isong/invitation/get-invitation-list', 'POST', data), // 获取邀请列表
  rewardList: (data: Invitation.List.Body) =>
    request<Invitation.RewardList.Data>('/isong/invitation/get-reward-list', 'POST', data), // 获取邀请奖励列表
  getActivityRule: () => request<string>('/isong/invitation/get-activity-rule', 'POST'), // 获取活动规则
  getConfiguration: () =>
    request<Invitation.GetConfiguration.Data>('/isong/invitation/get-reward-configuration', 'POST'), // 获取邀请奖励配置
};

/**
 * 榜单
 */
const TopList = {
  top10: (data: TopList.Top10.Query) => request<TopList.Top10.Data[]>('/isong/rank-record/list', 'GET', data), // 获得当前榜单列表-显示前10名
  historyList: (data: TopList.HistoryList.Query) =>
    request<TopList.HistoryList.Data>('/isong/rank-record/history-page', 'GET', data), // 获得当前榜单列表-显示前10名
  historyListTop: (data: { id: number }) =>
    request<TopList.Top10.Data[]>('/isong/rank-record/history-list', 'GET', data), // 获得当前榜单列表-显示前10名
  getCurrentTime: (data: TopList.Top10.Query) => request<string>('/isong/rank-record/get-current-time', 'GET', data), // 获得当前榜单统计时间
  getHistoryTime: (data: { id: number }) => request<string>('/isong/rank-record/get-history-time', 'GET', data), // 获得历史榜单统计时间
};

/**
 * 充值相关
 */
const Pay = {
  list: () => request<Pay.List.Data[]>('/isong/transaction/get/package/list', 'GET'), // 获得钱包充值套餐列表
  point: (data: Pay.Point.Body) => request<Pay.Point.Data>('/isong/transaction/create/point', 'POST', data), // 购买A豆
  submit: (data: Pay.Submit.Body) => request<Pay.Submit.Data>('/pay/order/submit', 'POST', data), // 提交支付订单
  record: (data: Pay.Record.Query) => request<Pay.Record.Data>('/isong/transaction/get-order-page', 'POST', data), // 充值记录
  profitPage: (data: Pay.ProfitPage.Query) =>
    request<Pay.ProfitPage.Data>('/isong/transaction/profit-page', 'GET', data), // 获得个人收入分页接口
  withdrawalPage: (data: Pay.WithdrawalPage.Query) =>
    request<Pay.WithdrawalPage.Data>('/isong/transaction/withdrawal-page', 'GET', data), // 获得用户提现记录接口
  brokeragePrice: () => request<Pay.BrokeragePrice.Data>('/isong/transaction/get/brokerage-price', 'GET'), // 获得当前可提现金额
  createWithdrawal: (data: Pay.CreateWithdrawal.Body) =>
    request<Pay.CreateWithdrawal.Data>('/isong/transaction/create-withdrawal', 'POST', data), // 提现
  rechargeWithRechargeCard: (data) => request('/isong/transaction/create/point/by-card', 'POST', data)
};

/**
 * 广告位模块
 */
const Ad = {
  config: () => request<Ad.Config.Data>('/isong/advertising-space/get-buy-config', 'POST'), // 获取广告位配置信息
  buyList: (data: Ad.BuyList.Body) =>
    request<Ad.BuyList.Data>('/isong/advertising-space/get-member-buy-list', 'POST', data), // 购买过的广告位列表
  creatOrder: (data: Ad.CreatOrder.Body) =>
    request<Ad.CreatOrder.Data>('/isong/transaction/create/adSpace', 'POST', data), // 创建购买广告位订单
  set: (data: Ad.Set.Body) => request<number>('/isong/advertising-space/set', 'POST', data), // 设置广告位
  payCancel: (data: Pay.PayCancel.Body) => request<number>('/isong/transaction/pay-cancel/adSpace', 'POST', data), // 充值记录
};

const News = {
  list: (data: any) => request('/isong/news/page', 'GET', data),
  detail: (data: any) => request('/isong/news/get', 'GET', data),
}

const Mv = {
  create: (data) =>  request('/isong/mv-video/create', 'POST', data),
  page: (data) =>  request('/isong/mv-video/page', 'GET', data),
  delete: (id) =>  request(`/isong/mv-video/delete?videoId=${id}`, 'DELETE'),
  get: (id) =>  request(`/isong/mv-video/get?id=${id}`, 'GET'),
  update: (data) =>  request('/isong/mv-video/update', 'PUT', data),
  publicPage: (data) =>  request('/isong/mv-video/show-page', 'GET', data),
}

const API = {
  Common,
  Index,
  Auth,
  User,
  Music,
  Order,
  Invitation,
  TopList,
  Pay,
  Ad,
  News,
  Mv
};
export default API;
